﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HZP.CKGL
{
    public partial class CPINFOFRM : Form
    {
        private BindingSource bsList = new BindingSource();
        public CPINFOFRM()
        {
            InitializeComponent();

            UTIL.InitDGVColumns(dgvList, new ColConfig[]
           {
                new ColConfig {ColName="排序",FieldName="PX",Editable=true },
                new ColConfig {ColName="产品名称",FieldName="CPMC",Editable=true,Width=150 },
                new ColConfig {ColName="产品型号",FieldName="CPXH",Editable=true,Width=150 },
           });
            dgvList.DataSource = bsList;
            showList();

            btnSave.Click += btnSave_Click;
            btnDel.Click += btnDel_Click;
        }

        private void showList()
        {
            bsList.DataSource = DB.CKGL.Query("select * from CPINFO order by PX");
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            DB.CKGL.Update(bsList.DataSource as DataTable, "select * from CPINFO where 1=2");
            showList();
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除记录吗？ 删除后便无法恢复！") == DialogResult.OK)
            {
                foreach (DataGridViewRow select in dgvList.SelectedRows)
                {
                    dgvList.Rows.Remove(select);
                }
                btnSave.PerformClick();
            }
        }
    }
}
